# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.shortcuts import render
from django.http import HttpResponse,JsonResponse
from dd_goods.models import *
import math
from django.core.serializers import serialize

# Create your views here.

def list(request):
    return render(request,'list.html')

def listData(request,id,num):
    start = int(num) * 10 - 10
    end = int(num) * 10
    type = TypeInfo.objects.get(pk=int(id))
    count = type.goodinfo_set.all().count()
    data = type.goodinfo_set.all()[start:end]
    pagecount = int(math.ceil(count / float(10)))
    # json_data = serialize("json", data)
    context = {"list":data,"pagecount":pagecount,'num':num}
    return render(request, 'list.html',context)